10 ' mandelx2.bas - FreeWare 2005
20 GOTO 60 ' begin
30 'SAVE "mandelx2.bas",A:LIST-30
40 GOTO 430 ' wait for key
50 GOTO 460 ' centered text
60 DEFDBL A,B,C,D,S,X,Y:SCREEN 12
70 CLS:PI=4*ATN(1):WINDOW (-320,-240)-(319,239)
80 DEFSTR M,Q:Q=MKI$(0)
90 DIM COL(8):DATA 0,1,9,2,10,4,12,14,6
100 FOR I=0 TO 8:READ COL(I):NEXT
110 DELH=PI:DELV=.75*PI:N1=240:N2=INT(N1*DELV/DELH)
120 M(1)="MANDELBROT idea from Hans Lauwerier"
130 M(2)="GWBASIC by Eric Tchong"
140 M(3)="Press any key to generate fractal"
150 FOR I=1 TO 3
160  GOSUB 50
170  IF I=2 THEN PRINT
180 NEXT:GOSUB 40:CLS
190 ' main
200 FOR I=0 TO N1
210  FOR J=0 TO N2
220   IF INKEY$<>"" THEN 400
230   A=DELH*I/N1:B=DELV*J/N2
240   X=PI/2:Y=0
250    FOR K=1 TO 64
260     IF ABS(Y)>12 THEN L=1+K MOD 8:K=2005:GOTO 330
270     U=EXP(Y):V=1/U:CH=(U+V)/2:SH=(U-V)/2
280     SS=SIN(X):CS=COS(X)
290     X1=A+PI*SS*CH:Y1=B+PI*CS*SH
300     DIST=ABS(X-X1)+ABS(Y-Y1)
310     IF DIST<.001 THEN L=3:GOTO 360
320     X=X1:Y=Y1
330    NEXT
340    IF K=2006 THEN 360
350    L=3
360    PSET (I,J),COL(L):PSET (I,-J),COL(L)
370    PSET (-I,J),COL(L):PSET (-I,-J),COL(L)
380  NEXT J
390 NEXT
400 GOSUB 40
410 SCREEN 0,0,0:CLS:END
420 ' wait for key
430 LSET Q=MKI$(0)
440 WHILE CVI(Q)=0:MID$(Q,1)=INKEY$:WEND:RETURN
450 ' centered text
460 X=(80-LEN(M(I)))/2
470 PRINT TAB(X) M(I):RETURN
